package org.hibernate;

import java.util.List;
import java.io.Serializable;
import javax.annotation.Resource;
import javax.persistence.EntityManager;

import org.hibernate.query.NativeQuery;

public class FactorySession {

    @Resource
    private EntityManager entityManager;

    private Session getSession() {
        return entityManager.unwrap(Session.class);
    }

    public <T> T load(Class<T> entityClass, Serializable id) {
        return getSession().load(entityClass, id);
    }

    public <T> T load(Class<T> entityClass, Serializable id, LockMode lockMode) {
        return getSession().load(entityClass, id, lockMode);
    }

    public <T> T get(Class<T> entityClass, Serializable id) {
        return getSession().get(entityClass, id);
    }

    public <T> T get(Class<T> entityClass, Serializable id, LockMode lockMode) {
        return getSession().get(entityClass, id, lockMode);
    }

    public Criteria createCriteria(Class persistentClass) {
        return getSession().createCriteria(persistentClass);
    }

    public Criteria createCriteria(Class persistentClass, String alias) {
        return getSession().createCriteria(persistentClass, alias);
    }

    public NativeQuery createSQLQuery(String queryString) {
        return getSession().createSQLQuery(queryString);
    }

    public Serializable save(Object object) {
        return getSession().save(object);
    }

    public void update(Object object) {
        getSession().update(object);
    }

    public void delete(Object object) {
        getSession().delete(object);
    }

    public void delete(List<Object> objects) {
        for (Object object : objects) {
            getSession().delete(object);
        }
    }

}
